package o;

import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.View.OnTouchListener;
import android.view.ViewConfiguration;
import android.view.ViewParent;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;

@RestrictTo({d.LIBRARY_GROUP})
public abstract class cm implements OnTouchListener, OnAttachStateChangeListener {
    private Runnable ʻ;
    private int ʼ;
    private Runnable ˊ;
    final View ˋ;
    private final float ˎ;
    private final int ˏ;
    private final int ॱ;
    private final int[] ॱॱ = new int[2];
    private boolean ᐝ;

    class c implements Runnable {
        final /* synthetic */ cm ˋ;

        c(cm cmVar) {
            this.ˋ = cmVar;
        }

        public void run() {
            ViewParent parent = this.ˋ.ˋ.getParent();
            if (parent != null) {
                parent.requestDisallowInterceptTouchEvent(true);
            }
        }
    }

    class e implements Runnable {
        final /* synthetic */ cm ˋ;

        e(cm cmVar) {
            this.ˋ = cmVar;
        }

        public void run() {
            this.ˋ.ˋ();
        }
    }

    public abstract bt ˎ();

    public cm(View view) {
        this.ˋ = view;
        view.setLongClickable(true);
        view.addOnAttachStateChangeListener(this);
        this.ˎ = (float) ViewConfiguration.get(view.getContext()).getScaledTouchSlop();
        this.ॱ = ViewConfiguration.getTapTimeout();
        this.ˏ = (this.ॱ + ViewConfiguration.getLongPressTimeout()) / 2;
    }

    public boolean onTouch(View view, MotionEvent motionEvent) {
        boolean z;
        boolean z2 = this.ᐝ;
        if (!z2) {
            boolean z3 = ˊ(motionEvent) && ˏ();
            if (z3) {
                long uptimeMillis = SystemClock.uptimeMillis();
                MotionEvent obtain = MotionEvent.obtain(uptimeMillis, uptimeMillis, 3, 0.0f, 0.0f, 0);
                this.ˋ.onTouchEvent(obtain);
                obtain.recycle();
            }
            z = z3;
        } else if (ˎ(motionEvent) || !ॱ()) {
            z = true;
        } else {
            z = false;
        }
        this.ᐝ = z;
        if (z || z2) {
            return true;
        }
        return false;
    }

    public void onViewAttachedToWindow(View view) {
    }

    public void onViewDetachedFromWindow(View view) {
        this.ᐝ = false;
        this.ʼ = -1;
        if (this.ˊ != null) {
            this.ˋ.removeCallbacks(this.ˊ);
        }
    }

    protected boolean ˏ() {
        bt ˎ = ˎ();
        if (!(ˎ == null || ˎ.ˎ())) {
            ˎ.ˊ();
        }
        return true;
    }

    protected boolean ॱ() {
        bt ˎ = ˎ();
        if (ˎ != null && ˎ.ˎ()) {
            ˎ.ˋ();
        }
        return true;
    }

    private boolean ˊ(MotionEvent motionEvent) {
        View view = this.ˋ;
        if (!view.isEnabled()) {
            return false;
        }
        switch (motionEvent.getActionMasked()) {
            case 0:
                this.ʼ = motionEvent.getPointerId(0);
                if (this.ˊ == null) {
                    this.ˊ = new c(this);
                }
                view.postDelayed(this.ˊ, (long) this.ॱ);
                if (this.ʻ == null) {
                    this.ʻ = new e(this);
                }
                view.postDelayed(this.ʻ, (long) this.ˏ);
                return false;
            case 1:
            case 3:
                ˊ();
                return false;
            case 2:
                int findPointerIndex = motionEvent.findPointerIndex(this.ʼ);
                if (findPointerIndex < 0 || ˋ(view, motionEvent.getX(findPointerIndex), motionEvent.getY(findPointerIndex), this.ˎ)) {
                    return false;
                }
                ˊ();
                view.getParent().requestDisallowInterceptTouchEvent(true);
                return true;
            default:
                return false;
        }
    }

    private void ˊ() {
        if (this.ʻ != null) {
            this.ˋ.removeCallbacks(this.ʻ);
        }
        if (this.ˊ != null) {
            this.ˋ.removeCallbacks(this.ˊ);
        }
    }

    void ˋ() {
        ˊ();
        View view = this.ˋ;
        if (view.isEnabled() && !view.isLongClickable() && ˏ()) {
            view.getParent().requestDisallowInterceptTouchEvent(true);
            long uptimeMillis = SystemClock.uptimeMillis();
            MotionEvent obtain = MotionEvent.obtain(uptimeMillis, uptimeMillis, 3, 0.0f, 0.0f, 0);
            view.onTouchEvent(obtain);
            obtain.recycle();
            this.ᐝ = true;
        }
    }

    private boolean ˎ(MotionEvent motionEvent) {
        View view = this.ˋ;
        bt ˎ = ˎ();
        if (ˎ == null || !ˎ.ˎ()) {
            return false;
        }
        ch chVar = (ch) ˎ.ᐝ();
        if (chVar == null || !chVar.isShown()) {
            return false;
        }
        boolean z;
        MotionEvent obtainNoHistory = MotionEvent.obtainNoHistory(motionEvent);
        ˊ(view, obtainNoHistory);
        ˎ(chVar, obtainNoHistory);
        boolean ॱ = chVar.ॱ(obtainNoHistory, this.ʼ);
        obtainNoHistory.recycle();
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 1 || actionMasked == 3) {
            z = false;
        } else {
            z = true;
        }
        if (ॱ && r0) {
            z = true;
        } else {
            z = false;
        }
        return z;
    }

    private static boolean ˋ(View view, float f, float f2, float f3) {
        return f >= (-f3) && f2 >= (-f3) && f < ((float) (view.getRight() - view.getLeft())) + f3 && f2 < ((float) (view.getBottom() - view.getTop())) + f3;
    }

    private boolean ˎ(View view, MotionEvent motionEvent) {
        int[] iArr = this.ॱॱ;
        view.getLocationOnScreen(iArr);
        motionEvent.offsetLocation((float) (-iArr[0]), (float) (-iArr[1]));
        return true;
    }

    private boolean ˊ(View view, MotionEvent motionEvent) {
        int[] iArr = this.ॱॱ;
        view.getLocationOnScreen(iArr);
        motionEvent.offsetLocation((float) iArr[0], (float) iArr[1]);
        return true;
    }
}
